const { ipcMain } = require('electron');

// 导入所有IPC处理函数
const { openFileDialogFn, openDirectoryDialogFn, saveFileDialogFn } = require('./dialog-handlers');
const { extractFramesFn } = require('./extract-frames-handler');
const { imagesToGifFn } = require('./images-to-gif-handler');
const { createPdfFn } = require('./create-pdf-handler');
const { trimSvgFn } = require('./trim-svg-handler');
const { resizeImagesFn } = require('./resize-images-handler');
const { parseHarFileFn } = require('./har-image-extractor-handler');
const { batchRenameDirectoriesFn } = require('./batch-rename-directories-handler');
const { compressZipFn } = require('./compress-zip-handler');
const { pdfToImagesFn } = require('./pdf-to-images-handler');

// 注册所有IPC处理函数
function registerAllIpcHandlers(defaultFfmpegPath, mainWindow) {
  // 文件选择对话框
  ipcMain.handle('open-file-dialog', async (event, options) => openFileDialogFn(event, options));
  ipcMain.handle('open-directory-dialog', async (event, options) => openDirectoryDialogFn(event, options));
  ipcMain.handle('save-file-dialog', async (event, options) => saveFileDialogFn(event, options));

  // 提取视频帧功能
  ipcMain.handle('extract-frames', async (event, config) => extractFramesFn(event, config, defaultFfmpegPath, mainWindow));

  // 图片转GIF功能
  ipcMain.handle('images-to-gif', async (event, config) => imagesToGifFn(event, config, defaultFfmpegPath, mainWindow));

  // 图片转PDF功能
  ipcMain.handle('create-pdf', async (event, config) => createPdfFn(event, config, mainWindow));
  ipcMain.handle('trim-svg', async (event, config) => trimSvgFn(event, config, mainWindow));
  ipcMain.handle('resize-images', async (event, config) => resizeImagesFn(event, config, mainWindow));
  
  // HAR图片提取功能
  ipcMain.handle('parse-har-file', async (event, config) => parseHarFileFn(event, config, mainWindow));
  
  // 目录批量重命名功能
  ipcMain.handle('batch-rename-directories', async (event, baseDir) => batchRenameDirectoriesFn(event, baseDir));

  // 压缩目录功能
  ipcMain.handle('compress-zip', async (event, config) => compressZipFn(event, config, mainWindow));

  // PDF转图片功能
  ipcMain.handle('pdf-to-images', async (event, config) => pdfToImagesFn(event, config, mainWindow));
}

module.exports = { registerAllIpcHandlers };
